/**
 * Package:com.afteryuan.server.service.impl;
 * $Id$
 * Copyright(c) 2001-2005 www.afteryuan.com
 */
package com.afteryuan.server.service.impl;

import com.afteryuan.server.command.down.CommandDown;
import com.afteryuan.server.data.Room;
import com.afteryuan.server.data.Sprite;
import com.afteryuan.server.data.SpritePool;
import com.afteryuan.server.service.SpriteService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Collection;

/**
 * SceneServiceImpl
 * <p/>
 * <p><a href="SceneServiceImpl.java.html"><i>View Source</i></a></p>
 *
 * @author <a href="mailto:afteryuan@afteryuan.com">$Author$</a>
 * @version $Revision$
 */
public class SpriteServiceImpl implements SpriteService {
    private static Log log = LogFactory.getLog(SpriteServiceImpl.class);
    SpritePool spritePool;

    public void setSpritePool(SpritePool spritePool) {
        this.spritePool = spritePool;
    }

    public void broadcast(CommandDown commandDown) {
        Collection<Sprite> sprites = spritePool.listAll();
        broadcast(sprites, commandDown);
    }

    public void broadcast(Room room, CommandDown commandDown) {
        Collection<Sprite> sprites = spritePool.listOfRoom(room);
        broadcast(sprites, commandDown);
    }

    public void broadcast(Collection<Sprite> sprites, CommandDown commandDown) {
        if(sprites==null)return; 
        for (Sprite sprite : sprites) {
            sprite.getConnectSession().write(commandDown);
        }
    }
}
